import Vue from 'vue'
import VueRouter from 'vue-router'
// 登录
import Login from '../views/Login/index.vue'
// 首页
import Home from '../views/Home/index.vue'
// 首页-重定向
import Welcome from '../views/Home/welcome.vue'
// 首页-显示全部
import ShowAll from '../views/Home/components/showAll.vue'
// 首页-手术详情
import Details from '../views/Home/components/details.vue'
// 综合档案
import Synthesis from '../views/Synthesis/index.vue'
// 综合档案-搜索内容
import SearchContent from '../views/Synthesis/searchContent.vue'
// 统计分析
import Statistics from '../views/Statistics/index.vue'
// 手术分析
import Surgery from '../views/Surgery/index.vue'
// 第三方应用
import Third from '../views/Third/index.vue'
// 在线直播
import Lives from '../views/Lives/index.vue'
// 在线直播-直播详情
import LiveMessage from '../views/Lives/components/liveMessage.vue'
// 个人信息
import PersonalMessage from '../views/personalMessage/index.vue'
// 配置管理
import SystemLayout from '../views/SystemLayout/index.vue'
// 配置管理-系统信息
import SystemMessage from '../views/SystemMessage/index.vue'
// 配置管理-用户管理
import UserManagement from '../views/UserManagement/index.vue'
// 配置管理-角色管理
import RoleManagement from '../views/roleManagement/index.vue'
// 配置管理-菜单管理
import MenuManagement from '../views/MenuManagement/index.vue'
// 配置管理-系统日志
import SystemLog from '../views/SystemLog/index.vue'
// 配置管理-数据库信息
import DataBase from '../views/DataBase/index.vue'
// 配置管理-数据库信息-表信息展示
import ColumnList from '../views/DataBase/columnList.vue'
// 配置管理-分布式节点配置
import Distributed from '../views/Distributed/index.vue'
// 配置管理-报告配置
import Report from '../views/Report/index.vue'
// 配置管理-综合档案模板配置
import Comprehensive from '../views/Comprehensive/index.vue'
// 配置管理-第三方应用程序配置
import ThirdUse from '../views/ThirdUse/index.vue'

Vue.use(VueRouter)

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    meta: { title: '登录' },
    name: 'Login',
    redirect: '/login',
    component: Login,
  },
  {
    path: '/home',
    name: 'Home',
    redirect: '/welcome',
    component: Home,
    children: [
      {
        path: '/welcome',
        meta: { title: '首页' },
        name: 'Welcome',
        component: Welcome,
      },
      {
        path: '/showAll',
        meta: { title: '显示全部' },
        name: 'ShowAll',
        component: ShowAll,
      },
      {
        path: '/details',
        meta: { title: '手术详情' },
        name: 'Details',
        component: Details,
      },
      {
        path: '/synthesis',
        meta: { title: '综合档案' },
        name: 'Synthesis',
        component: Synthesis,
      },
      {
        path: '/searchContent',
        name: 'SearchContent',
        component: SearchContent,
      },
      {
        path: '/statistics',
        meta: { title: '统计分析' },
        name: 'Statistics',
        component: Statistics,
      },
      {
        path: '/surgery',
        meta: { title: '手术分析' },
        name: 'Surgery',
        component: Surgery
      },
      {
        path: '/third',
        meta: { title: '第三方应用' },
        name: 'Third',
        component: Third
      },
      {
        path: '/lives',
        meta: { title: '在线直播' },
        name: 'Lives',
        component: Lives,
      },
      {
        path: '/liveMessage',
        name: 'LiveMessage',
        meta: { title: '直播详情' },
        component: LiveMessage
      },
      {
        path: '/personalMessage',
        meta: { title: '我的资料' },
        name: 'PersonalMessage',
        component: PersonalMessage
      },
      {
        path: '/systemLayout',
        meta: { title: '配置管理' },
        name: 'SystemLayout',
        component: SystemLayout,
        children:[
          {
            path: '/systemMessage',
            meta: { title: '系统信息' },
            name: 'SystemMessage',
            component: SystemMessage,
          },
          {
            path: '/userManagement',
            meta: { title: '用户管理' },
            name: 'UserManagement',
            component: UserManagement,
          },
          {
            path: '/roleManagement',
            meta: { title: '角色管理' },
            name: 'RoleManagement',
            component: RoleManagement,
          },
          {
            path: '/menuManagement',
            meta: { title: '菜单管理' },
            name: 'MenuManagement',
            component: MenuManagement
          },
          {
            path: '/systemLog',
            meta: { title: '系统日志' },
            name: 'SystemLog',
            component: SystemLog
          },
          {
            path: '/dataBase',
            meta: { title: '数据库信息' },
            name: 'DataBase',
            component: DataBase
          },
          {
            path: '/columnList',
            meta: { title: '表信息展示' },
            name: 'ColumnList',
            component: ColumnList
          },
          {
            path: '/distributed',
            meta: { title: '分布式节点配置' },
            name: 'Distributed',
            component: Distributed,
          },
          {
            path: '/report',
            meta: { title: '报告配置' },
            name: 'Report',
            component: Report
          },
          {
            path: '/comprehensive',
            meta: { title: '综合档案模板配置' },
            name: 'Comprehensive',
            component: Comprehensive
          },
          {
            path: '/thirdUse',
            meta: { title: '第三方应用程序配置' },
            name: 'ThirdUse',
            component: ThirdUse
          },
        ]
      },
      
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login/index.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  let seleToken = window.sessionStorage.getItem('token');
  if (!seleToken) return next('/login')
  next()
})

export default router
